/* The Generic Node. Stores generic data and links to next node for generic data structures
 * Tyler Wozniak & Andrew Hall
 */


#ifndef NODE
#define NODE
#include "imports.h"

template<typename T>
struct Node{
	T data;				//Data, of type T
	Node<T>* nextNode;	//The next node in the data structure
	int index;			//The index of this node

	//Basic constructors for various amounts of info
	Node(T Data) : data(Data),index(0),nextNode(NULL) { }
	Node(T Data, int Index): data(Data), index(Index), nextNode(NULL) {}
	Node(T Data, int Index, Node<T>& next): data(Data), index(Index), *nextNode(next) { }
	Node(T Data, int Index, Node<T>* next): data(Data), index(Index), nextNode(*next) { }

	//Copy constructor
	Node(const Node<T>& other)
	{
		this->data = other.data;
		this->nextNode = other.nextNode;
		index = -1; //This will allow for checking indexes that get broken so that
					//we can know to reindex in those situations
	}
	
	//Copy assignment operator.  Note:
	//Index is not changed because an index shouldn't change if you're just modifying this node
	Node<T> operator=(const Node<T>& other)
	{
		this->data = other.data;
		this->nextNode = other.nextNode;

		return *this;
	}

	//Destructor. NOTE: YOU MUST ALWAYS TAKE CARE OF THE NEXT NODE OR YOU WILL LEAK MEMORY
	~Node()
	{
		nextNode = NULL;
		delete nextNode;
	}
};

#endif